from django import forms

from demo.models import Classes, Label


class ArticleForm(forms.Form):
    title = forms.CharField(
        label="标题",
        min_length=2,
        max_length=50,
        error_messages={
            "min_length": "标题长度至少2个字符",
            "max_length": "标题长度不能超过20个字符"
        }
    )
    desc = forms.CharField(
        label="描述",
        min_length=2,
        max_length=200,
        error_messages={
            "min_length": "描述长度至少2个字符",
            "max_length": "描述长度不能超过200个字符"
        }
    )
    content = forms.CharField(
        label="内容",
        widget=forms.Textarea,
    )
    cover = forms.FileField(
        label="封面",
        required=False,
    )
    # 分类--只能单选
    classes = forms.ModelChoiceField(
        label="分类",
        queryset=Classes.objects.all(),
        required=False,
    )
    labels = forms.ModelMultipleChoiceField(
        label="标签",
        queryset=Label.objects.all(),
        required=False,
    )